<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    var totalMoney = function (n) {
      const div = Math.floor(n / 7), r = n % 7
      return div * (div + 7) * 7 / 2 + (r + 1) * r / 2 + div * r
    };
    console.log(totalMoney(4));
  </script>
</body>

</html>